﻿#include "coleditobjectdialog.h"
#include "ui_coleditobjectdialog.h"
#include <QSqlQuery>
int COLeditobjectDialog::ID;
COLeditobjectDialog::COLeditobjectDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::COLeditobjectDialog)
{
    ui->setupUi(this);
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("添加信息状态：");
    connect(ui->cancelbtn,SIGNAL(clicked(bool)),this,SLOT(close()));
}

COLeditobjectDialog::~COLeditobjectDialog()
{
    delete ui;}


void COLeditobjectDialog::receivestr(QStringList str)
{
//获取传递过来的数据
ID=str.at(0).toInt();
ui->object->setText(str.at(1));
ui->unit->setText(str.at(2));
ui->duty->setText(str.at(3));
ui->politic->addItem("");
QString judge=QString("select Politic from ZZB.PoliticCode ");
QSqlQuery query;
int i=0,j=0;
query.exec(judge);
while(query.next())
{
    i++;
    QString z=query.value(0).toString();
    ui->politic->addItem(z);
    if(z==str.at(4)){
        j=i;
    }
}
ui->politic->setCurrentIndex(j);
ui->copies->setText(str.at(5));
}


void COLeditobjectDialog::on_ackbtn_clicked()
{
    if(ui->copies->text().isEmpty()||ui->object->text().isEmpty()||ui->unit->text().isEmpty()){
         ui->status->setText("修改信息状态:对象人及单位，份数不能为空!");
    }else{
        QSqlQuery query;
        query.prepare("update Object set Objectman=?,Objectunit=?,Objectduty=?,politicstatus=?,copies=? where ObjectID = ?");
        query.addBindValue(ui->object->text());
        query.addBindValue(ui->unit->text());
        query.addBindValue(ui->duty->text());
        query.addBindValue(ui->politic->currentText());
        query.addBindValue(ui->copies->text());
        query.addBindValue(ID);
        bool ok=query.exec();
        if(ok)
        {ui->status->setText("修改信息状态:修改成功");
                this->close();}
        else
        {ui->status->setText("修改信息状态:修改失败");}
    }
}
